<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>举报应用</title>
<link href="common/css/base.css" rel="stylesheet" type="text/css" />
<style type="text/css">
    .textarea { width: 430px; height: 69px; padding: 5px; background: url(images/txtarea.png) no-repeat; border: none; color: #333; margin-bottom: 15px; }
	.textareaBox {display: none;}
	.form-item p { padding: 10px 0; text-align: center;}
	a.suggest_item,a.suggest_active { display: block; width: 401px; padding: 12px 20px 13px 59px; border-top: 1px solid #6c6c6c; font-size: 24px; background: url(images/btn_radio_off.png) no-repeat 10px center;}
	a.suggest_active {background: url(images/btn_radio_on.png) no-repeat 10px center;}
	span.limit_num { display: block; width: 90%; margin: 0 auto; clear: both; text-align: right; padding: 5px 0; }
	span.limit_num .num { color: #f00;}
	.form-item p { padding: 10px 0; text-align: center;}
	.title_bar { height: 35px; padding: 0 20px 0 10px; background:url(images/title_bar.gif) repeat-x;  color: #a0a0a0; line-height: 35px; font-weight: bold}
	.btn,.btn_hover { height: 41px; border: 1px solid #242424; border-radius: 10px; font-size: 22px; background: url(images/btn_bg.png) repeat-x 0 0; color: #fff;} 
	.btn_hover {background: url(images/btn_bg.png) repeat-x 0 -41px; border: 1px solid #353538;}
	.btn272 { width: 272px; height: 43px; }
</style>
<script type="text/javascript" src="common/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="/ams/lephone/2.5/common/lephone/js/lang-zh.js"></script>
<script type="text/javascript" src="/ams/lephone/2.5/common/lephone/js/common.js"></script>
<script type="text/javascript" src="/ams/lephone/2.5/common/lephone/js/jquery.cookie.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	$(".suggest_item").click(function(){
		$(this).addClass("suggest_active");
		$(this).siblings().removeClass("suggest_active");
		var thisText = $(this).text(); 
		var thisValue = $(this).attr("value");
		
	   	$("#reportType").val(thisValue);
	   	$("#suggest_form .textareaBox").hide();
	})
	$(".suggest_item:last").click(function(){
	    $("#suggest_form .textareaBox").show();
	})
	
	$("#report_submit").click(function(){
		addReport();
	})
	$("#reportType").val("");
	$("#reportContent").val("");

	var limitCommentNum = function(){
	     vals = $.trim($("#reportContent").val());
		 var num = vals.length;
		 $(".limit_num .num").text(200-num);
		 if(num>200){
		        tmpString = vals.substring(0,200);
		        $(".limit_num .num").text(0);
		        $("#reportContent").val(tmpString);
		    	showToast(lang.suggest_msg1,0);//举报内容不能超过200个字
				return true;
		 } 
	}
	$("#reportContent").after("<span class='limit_num'>"+lang.limit_num+"<b class='num'>200</b>/200</span>").bind('keyup',limitCommentNum);
	setInterval(limitCommentNum,500);
})
function locationTo(url) {
	location.href = url;
}
function addReport(){
	showLoading("正在提交...");
	
	var reportType = $("#reportType").val();
	
	if(reportType == ""){
		showToast("请选择一项举报内容",0);
		$("#wrapper").show();
        hideLoading();
		return true;
	}
	
    var rcValue= $("#reportContent").val();
	var len = $.trim(rcValue).length;
	/*if(reportType == "0" && len > 200){
		showToast("举报内容限200字以内",0);
		$("#wrapper").show();
        hideLoading();
		return false;
	}*/
	if(reportType == "0" && (rcValue == "" || len == 0)){
		showToast("请填写举报内容",0);
		$("#wrapper").show();
        hideLoading();
		return true;
	}
	var reportContent = encodeURIComponent(rcValue);
	var paramSTR = "reporttype=" + reportType +"&reportcontent="+reportContent;
	
	var requestUri = "/ams/2.5/addreportdata.do?lcaid=<%=request.getParameter("lcaid")%>";
	var responseUrl = "/ams/lephone/2.5/appinfo.do?lcaid=<%=request.getParameter("lcaid")%>";
	var successMessage = "举报成功";
	var lostMessage = "举报失败";
	var registerMessage = "注册客户端失败";
	var loginMessage = "登录失败";
	amsAjax("post",requestUri,paramSTR,responseUrl,2000,successMessage,lostMessage,registerMessage,loginMessage,10000);
	
}



	function amsAjax(requestType,requestUri,param,responseUrl,responseTimeOut,successMessage,lostMessage,registerMessage,loginMessage,sendTimeOut){
		var vstatus=0;
		var html = $.ajax({
			type: requestType,
			url: requestUri,
			async: false,
			data:   param,
			timeout :sendTimeOut, 
          	success: function(msg){
				vstatus = 200;
          	},
			error: function(XMLHttpRequest, textStatus){
				if(textStatus == "timeout"){
					vstatus = 408;
				}else if(textStatus == "error"){
					hideLoading();
					$(".form-item").show();
					if(XMLHttpRequest.status == 401){
						//showLoading("正在获取登录信息...");
						var st = prompt("newst","");
						//alert(st);
						//hideLoading();
						if(st != ""){
							$.cookie('lpsust', st , {expires: 7, path: '/'});
							vstatus = 401;
						}else{
							vstatus = 402;
						}
					}else if(XMLHttpRequest.status == 308){
	            				//showLoading("正在注册客户端信息...");
						var clientId = prompt("newclientid","");
						//hideLoading();
						if(clientId != ""){
							$.cookie('clientid', clientId , {expires: 7, path: '/'});
							vstatus=308;
							//amsAjax(requestType,requestUri,param,respnseUrl,responseTimeOut);
						}else{
							vstatus=309;
						}
					}
				}
			}
		});
		if(vstatus == 200){
			hideLoading();          	
			setTimeout(locationTo(responseUrl),responseTimeOut);
			showLoading(successMessage);//评论成功
			//showToast("评论成功",1);
 	        
		}else if(vstatus == 401){
			var av_status = amsAjaxAgain(requestType,requestUri,param,responseTimeOut,sendTimeOut);
			if(av_status == 200){
				hideLoading();
				clearTimeout();
				setTimeout(locationTo(responseUrl),responseTimeOut);
				showLoading(successMessage);//评论成功
				//showToast("评论成功",1);
				//alert(responseUrl);
				//cc.locationTo(responseUrl);
			}else if(av_status == 308){
				/** 401之后308处理 */
				//alert("评论失败:"+av_status);
				//showToast("注册客户端失败",1);
				var av_status = amsAjaxAgain(requestType,requestUri,param,responseTimeOut,sendTimeOut);
				if(av_status == 200){
					hideLoading();
					//clearTimeout();
					setTimeout(locationTo(responseUrl),responseTimeOut);
					showLoading(successMessage);//评论成功
				}else if(av_status == 408){
					showToast("服务器超时",1);
				}else {
					showToast(lostMessage,1);//评论或评分失败
				}
			}else if(av_status == 309){
				showToast(registerMessage,1);//注册客户端信息失败
			}else if(av_status == 408){
				showToast("服务器超时",1);
			}else {
				showToast(lostMessage,1);//评论或评分失败
			}
		}else if(vstatus == 402){
			showToast(loginMessage,1);//获取登录信息失败
		}else if(vstatus == 308){
			/** 第一次308处理 */
			var av_status = amsAjaxAgain(requestType,requestUri,param,responseTimeOut,sendTimeOut);
			if(av_status == 200){
				hideLoading();
				setTimeout(locationTo(responseUrl),responseTimeOut);
				showLoading(successMessage);//评论成功
			}else if(av_status == 408){
				showToast("服务器超时",1);
			}else{
				showToast(lostMessage,1);//评论或评分失败
			}
		}else if(vstatus == 309){
			showToast(registerMessage,1);//注册客户端信息失败
		}else if(vstatus == 408){
			showToast("服务器超时",1);
		}else{
			showToast(lostMessage,1);//评论或评分失败
		}

	}


	function amsAjaxAgain(requestType,requestUri,param,responseTimeOut,sendTimeOut){
		var v_status=0;
		$.ajax({
			type: requestType,
			url: requestUri,
			async: false,
			data:   param,
			timeout :sendTimeOut,
           	success: function(msg){
				v_status = 200;
           	},
			error: function(XMLHttpRequest, textStatus){
				if(textStatus == "error"){
					hideLoading();
					$(".form-item").show();
					if(XMLHttpRequest.status == 401){
						v_status = 401;
						//showToast(loginMessage,1);//获取登录信息失败
					}else if(XMLHttpRequest.status == 308){
	            		showLoading("正在注册客户端信息...");
						var clientId = prompt("newclientid","");
						hideLoading();
						if(clientId != ""){
							$.cookie('clientid', clientId , {expires: 7, path: '/'});
							v_status = 308;						
						}else{
							v_status = 309;
						}
					}else{
						v_status = XMLHttpRequest.status;
						//showToast(lang.comment_msg4,1);//评论或评分失败
					}
				}else if(textStatus == "timeout"){
					v_status = 408;
				}
			}
		});
		return v_status;
	}









</script>
</head>
<body>
<div id="wrapper" style="width: 480px;">
  <div class="title_bar">举报内容</div>
  <a class="suggest_item" href="javascript: void(0)" value="1">损害国家荣誉和利益</a>
  <a class="suggest_item" href="javascript: void(0)" value="2">煽动民族仇恨</a>
  <a class="suggest_item" href="javascript: void(0)" value="3">宣扬邪教和封建迷信</a>
  <a class="suggest_item" href="javascript: void(0)" value="4">色情内容</a>
  <a class="suggest_item" href="javascript: void(0)" value="5">暴力画面</a>
  <a class="suggest_item" href="javascript: void(0)" value="6">憎恨或谩骂内容</a>
  <a class="suggest_item" href="javascript: void(0)" value="0">其他反对意见</a>
  <div class="form-item" id="suggest_form" style="padding-top: 0;">
    <p class="textareaBox">
      <textarea id="reportContent" name="textarea" cols="" rows="" class="textarea"></textarea>
      <input type="hidden" value="" id="reportType"></input>
	</p>
	<p>
		<input id="report_submit" name="" type="button" value="提交" class="btn btn272" />
    </p>
  </div>
</div>

</body>
</html>

